/* RGB Flashing Random Colors
 
 This example shows how to display solid colors using digital write and how to generate a random number and output PWM with analogWrite() function.
 
 The circuit:
 * V+ for RGB LED attached to digital pin 8.
 * Green inside RGB LED attached to digital pin 9.
 * Blue inside RGB LED attached to digital pin 10.
 * Red inside RGB LED attached to digital pin 11.
 by: Joe Riera   9-16-2011
*/

const int LedV = 8;          // V+ for RGB LED
const int LedRed = 9;        // Red Color of RGB
const int LedGrn = 10;       // Green Color of RGB
const int LedBlu = 11;       // Blue Color od RGB
long unsigned int delaytime = 1000; 
int LedRedValue, LedBluValue, LedGrnValue; // Temp Variables to store random numbers we generate.

void setup()  { 
  pinMode(LedRed, OUTPUT);   // sets the pins as outputs
  pinMode(LedGrn, OUTPUT);   
  pinMode(LedBlu, OUTPUT); 
  pinMode(LedV, OUTPUT); 
  pinMode(13, OUTPUT);   
} 

void loop()  { 
  digitalWrite(LedV, HIGH);    // Set High for V+ on LED, Aprox 30ma 
  
  digitalWrite(LedRed, LOW);  // Red 
  digitalWrite(LedBlu, HIGH);
  digitalWrite(LedGrn, HIGH);
  delay(delaytime);
  
    digitalWrite(13, HIGH);   // set the LED on to inicate end of cycle
  delay(delaytime);
  digitalWrite(13, LOW);    // set the LED off
  delay(delaytime);
  
  digitalWrite(LedRed, HIGH);  
  digitalWrite(LedBlu, LOW);    // Blue
  digitalWrite(LedGrn, HIGH);
  delay(delaytime);
  
    digitalWrite(13, HIGH);   // set the LED on to inicate end of cycle
  delay(delaytime);
  digitalWrite(13, LOW);    // set the LED off
  delay(delaytime);
  
  digitalWrite(LedRed, HIGH);
  digitalWrite(LedBlu, HIGH);
  digitalWrite(LedGrn, LOW);    // Green
  delay(delaytime);
  
  analogWrite(LedRed, 1);       // Yellow  using PWM
  analogWrite(LedBlu, 255);
  analogWrite(LedGrn, 1);
  delay(delaytime);
     
  analogWrite(LedRed, 1);        // Orange using PWM
  analogWrite(LedBlu, 255);
  analogWrite(LedGrn, 102);
  delay(delaytime);
     
       digitalWrite(13, HIGH);   // set the LED on to inicate end of cycle
  delay(delaytime);
  digitalWrite(13, LOW);    // set the LED off
  delay(delaytime);
     
  analogWrite(LedRed, 1);       // Purple using PWM
  analogWrite(LedBlu, 1);
  analogWrite(LedGrn, 255);
  delay(delaytime);
     
       digitalWrite(13, HIGH);   // set the LED on to inicate end of cycle
  delay(delaytime);
  digitalWrite(13, LOW);    // set the LED off
  delay(delaytime);
  
  analogWrite(LedRed, 255);     // Aqua using PWM
  analogWrite(LedBlu, 1);
  analogWrite(LedGrn, 1);
   delay(delaytime);
   
  int LedRedValue = random(1,255);  // Generate random value between 1 and 255
  int LedBluValue = random(1,255);
  int LedGrnValue = random(1 ,255);
 
  analogWrite(LedRed, LedRedValue);  // Set Random values for output
  analogWrite(LedBlu, LedBluValue);
  analogWrite(LedGrn, LedGrnValue);

  digitalWrite(13, HIGH);   // set the LED on to inicate end of cycle
  delay(delaytime);
  digitalWrite(13, LOW);    // set the LED off
  delay(delaytime);
}

